package com.base.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.base.po.voip.Payinfoes;
import com.base.service.PayinfoesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.base.po.sqlparam.RechargeratiosExamplePage;
import com.base.po.voip.Rechargeratios;

import com.base.po.voip.RechargeratiosExample.Criteria;
import com.base.service.RechargeratiosService;


/**
 * admin管理系统控制器
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin")
public class content_zaixianchongzhi {
	@Autowired
	private RechargeratiosService rechargeratiosService;
	@Autowired
	private PayinfoesService payinfoesService;
	
	
	// 用户首页
	@RequestMapping("/content_zaixianchongzhi")
	public ModelAndView index(HttpServletRequest request) throws Exception {
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();
		RechargeratiosExamplePage examplePage = new RechargeratiosExamplePage();
		examplePage.setOrderByClause("CreateTime");
		examplePage.pagesize = 10;
		examplePage.start = 0;
		examplePage.rows = examplePage.pagesize;// 设置首次分页
		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
		List<Rechargeratios> rechargeratios = null;
		examplePage.setOrderByClause("Grade DESC");
		Criteria criteria = examplePage.createCriteria();
		criteria.andAgentidEqualTo(adminUserId).andDatastatusEqualTo(true);
		/*
		 * 设置分页
		 */
		int totlenum = rechargeratiosService.countByExample(examplePage);// 页面总数
		request.setAttribute("totlenum", totlenum);// 传入session中
		request.setAttribute("curPage", 1);// 传入session中
		rechargeratios = rechargeratiosService.selectByExamplePage(examplePage);
		/*
		 * 在线充值数据统计
		 */
		Payinfoes payinfoes = payinfoesService.selectByShopCountMoney(adminUserId);
		if (rechargeratios != null) {
			
			// 设置页面进行跳转
			modelAndView.setViewName("jsp/content_zaixianchongzhi");
			request.setAttribute("adminUsergrade", adminUsergrade);
			request.setAttribute("list", rechargeratios);
			request.setAttribute("countMoney", payinfoes.getCountMoney());
			request.setAttribute("countNum", payinfoes.getCountNum());
			return modelAndView;
		}
	
		modelAndView.setViewName("jsp/datanotfound");
		return modelAndView;

	}
	
	@RequestMapping("/selectZaixianchongzhi")
	public ModelAndView selectZaixianchongzhi(HttpServletRequest request, String id,Integer curPage) throws Exception {
	
		// 设置session缓存
		if (curPage == null) {
			if (request.getSession().getAttribute("curPage") != null) {
				curPage = (Integer) request.getSession().getAttribute("curPage");
			} else {
				curPage = 1;
			}
		}
		if (id == null) {
			if (request.getSession().getAttribute("id") != null) {
				id = (String) request.getSession().getAttribute("id");
			}
		}
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();
		RechargeratiosExamplePage examplePage = new RechargeratiosExamplePage();
		examplePage.setOrderByClause("CreateTime");
		examplePage.pagesize = 10;
		examplePage.start = 0;
		examplePage.rows = examplePage.pagesize;// 设置首次分页
		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
		List<Rechargeratios> rechargeratios = null;
		examplePage.setOrderByClause("Grade DESC");
		Criteria criteria = examplePage.createCriteria();
		criteria.andAgentidEqualTo(adminUserId).andDatastatusEqualTo(true);
		// 条件筛选
		if (id != null && !id.equals("")) {
			request.setAttribute("id", id);
			criteria = criteria.andIdEqualTo(id);
			examplePage.getOredCriteria().add(criteria);
		}
		/*
		 * 设置分页
		 */
		int totlenum = rechargeratiosService.countByExample(examplePage);// 页面总数
		request.setAttribute("totlenum", totlenum);// 总数据传入session中
		request.setAttribute("curPage", curPage);// 当前页面传入session中

		rechargeratios = rechargeratiosService.selectByExamplePage(examplePage);
		if (rechargeratios != null) {
			// 设置页面进行跳转
			modelAndView.setViewName("jsp/content_zaixianchongzhi");
			request.setAttribute("list", rechargeratios);
			return modelAndView;
		}
		modelAndView.setViewName("jsp/datanotfound");
		return modelAndView;
	}
}
